<ui:composition
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:c="http://java.sun.com/jstl/core"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:a4j="http://richfaces.org/a4j"
  xmlns:nxu="http://nuxeo.org/nxweb/util"
  xmlns:nxh="http://nuxeo.org/nxweb/html"
  xmlns:nxd="http://nuxeo.org/nxweb/document">
<div id="document_versions">

<c:if test="#{nxd:hasPermission(currentDocument, 'ReadVersion')
        and currentDocument.versionable
        and !(currentDocument.version or currentDocument.proxy)}">

  <h:panelGroup>

    <nxu:set var="selectedVersionList" value="#{versionList.entries}" cache="true">
      <c:if test="#{not empty selectedVersionList}">
        <h:form id="document_versions_form">
          <h:dataTable var="versionItemSelection" value="#{selectedVersionList}"
            class="dataOutput" rowClasses="dataRowEven,dataRowOdd">
            <h:column>
              <f:facet name="header" />
              <h:selectBooleanCheckbox value="#{versionItemSelection.selected}">
                <a4j:ajax id="ajax_onclick_#{versionItemSelection.data.id}"
                  event="click"
                  listener="#{documentListingActions.checkCurrentDocAndProcessVersionSelectRow(versionItemSelection, currentDocument.ref)}"
                  render="version_ajax_selection_buttons" />
              </h:selectBooleanCheckbox>
            </h:column>

            <h:column>
              <f:facet name="header">
                <h:outputText value="#{messages['label.version']}" />
              </f:facet>
              <h:outputText value="#{versionItemSelection.data.description}" />
            </h:column>

            <h:column>
              <f:facet name="header">
                <h:outputText value="#{messages['label.action']}" />
              </f:facet>
              <ui:insert name="document_versions_buttons" />
            </h:column>
          </h:dataTable>

          <a4j:outputPanel id="version_ajax_selection_buttons" layout="block">
            <div id="version_selection_buttons">
              <table>
                <tbody>
                  <tr>
                    <td>
                      <nxu:set var="actions"
                        value="#{webActions.getActionsList('CURRENT_VERSION_SELECTION_LIST', false)}"
                        cache="true"
                        useAlias="true">
                        <c:forEach var="sel_action" items="#{actions}">
                          <span id="#{sel_action.id}">
                            <nxh:commandButton
                              styleClass="button"
                              action="#{sel_action.getLink()}"
                              value="#{messages[sel_action.label]}"
                              onclick="#{sel_action.confirm}"
                              disabled="#{!sel_action.available}"
                              immediate="#{sel_action.immediate}"
                              id="#{sel_action.id}_button" />
                           </span>
                         </c:forEach>
                      </nxu:set>
                    </td>
                    <td valign="middle">
                      <a4j:status>
                        <f:facet name="start">
                          <h:graphicImage value="/img/standart_waiter.gif" />
                        </f:facet>
                      </a4j:status>
                    </td>
                  </tr>
                </tbody>
              </table>
            </div>
          </a4j:outputPanel>
        </h:form>
      </c:if>

      <c:if test="#{empty selectedVersionList}">
        <p>
          <h:outputText value="#{messages['label.noversion']}" />
        </p>
      </c:if>

    </nxu:set>

  </h:panelGroup>

</c:if>

</div>
</ui:composition>